<script src="<{$config.weburl}>/script/jquery-1.4.4.min.js" type="text/javascript"></script>
<script type="text/javascript" src="<{$config.weburl}>/script/jquery.validation.min.js"></script>
<header>
	<div class="nav-w">
    	<section class="nav-s"><a href="<{$config.weburl}>"><nav>首页</nav></a></section>
    	<section class="nav-c"><span>确认订单</span></section>
   		<section class="nav-e"></section>
    </div>
</header>
<link href="<{$config.weburl}>/templates/wap/css/product_order.css" rel="stylesheet" type="text/css" />
<section>
<{if $smarty.get.type=='login'}>
    <div class="w" style="margin:80px auto;">
        <a href="<{$config.weburl}>/login.php">请先登录</a>
    </div>
<{elseif  $smarty.get.type=='orders'}>
    <div class="w" style="margin:80px auto;">
        订单提交成功<br>
        <a href="<{$config.weburl}>/?m=product">继续购物</a>
        <a href="<{$config.weburl}>/main.php?m=product&s=admin_buyorder">进入后台</a>
    </div>
<{elseif $smarty.get.type=='orderf'}>
    <div class="w" style="margin:80px auto;">
    产品库存不足
    </div>
<{else}>
<{if $consignee.id}>
<form action="" method="post" id="form" name="form">
<input type="hidden" name="act" value="order" />
<input type="hidden" name="hidden_consignee_id" id="hidden_consignee_id" value="<{$consignee.id}>" />
<div class="order">
	<h2>收货地址</h2>
 	<div class="address">
        <a href="main.php?m=member&s=admin_orderadder&t=pro">
            <p><{$consignee.name}></p>
            <p><{$consignee.area}></p>
            <p><{$consignee.address}></p>
            <p><{$consignee.mobile}></p>
     	 </a>
    </div>
  	<h2>商品清单</h2>
 	<div>
	<{foreach item=list from=$cart}> 
	<div class="item">
        <div class="top">
            <a target="_blank" href="shop.php?uid=<{$list.sell_userid}>"><{$list.company}></a>
        </div>	
        
        <div>
        <{foreach item=pro from=$list.prolist}>
            <dl class="clearfix">
                <dt>
                    <a href="?m=product&s=detail&id=<{$pro.pid}>"><img height="80" alt="<{$pro.name}>" src="<{$pro.pic}>_220X220.jpg"></a>
                </dt>
                <dd>
                    <p class="p-name"><a href="?m=product&s=detail&id=<{$pro.pid}>"><{$pro.pname}></a></p>
                    <p class="p-price"><strong><{$config.money}><{$pro.price|number_format:2}></strong> X <{$pro.num}></p>
                    <p class="p-price">产品编号:<{$pro.code}></p>
                </dd>
            </dl>
        <{/foreach}>
        </div>
        <div class="bottom clearfix">
            <div class="p-detail">
            	配送方式：
                <{if $list.mail>0 or $list.express>0 or $list.ems>0}>
                <select id='cem_<{$list.sell_userid}>' onchange="count_price('<{$list.sell_userid}>');">
                <{if $list.express>0}>
                <option value="快递,<{$list.express}>">快递<{$config.money}><{$list.express|number_format:2}></option>
                <{/if}>
                <{if $list.mail>0}>
                <option value="平邮,<{$list.mail}>">平邮<{$config.money}><{$list.mail|number_format:2}></option>
                <{/if}>
                <{if $list.ems>0}>
                <option value="EMS,<{$list.ems}>">EMS<{$config.money}><{$list.ems|number_format:2}></option>
                <{/if}>
                </select>
                <{else}>
                卖家承担
                <{/if}>
                <{if $list.mail>0 or $list.express>0 or $list.ems>0}>
                    <span class="hidden" id="show_cem_<{$list.sell_userid}>">
                        <{$list.express|number_format:2}>
                    </span>
                <{/if}>
            </div>
        	<div class="fr">
            小计(含运费):&nbsp;&nbsp;
            <span class="p-name">
                <strong class="price">
                	<{$config.money}>
                    <em class="shop_total_price" id="s_csumprice_<{$list.sell_userid}>">
                    	<{$list.sumprice+$list.express|number_format:2}>
                    </em>
                </strong>
            </span>
            </div>
        </div>
    	   
    </div>	
    <{/foreach}>
	</div>
    <span class="p-price">应付总额：
        <strong><{$config.money}><span id="s_sumprice"></span></strong>
	</span>
    <div class="choose_btn">
        <a class="cart-button" id="submitToPay" href="javascript:void(0)">提交订单</a>
    </div>       
</div>
<script>
function count_price(id)
{	//计算单店铺
	v=$('#cem_'+id).val();
	value=v.split(',');
	
	$('#logistics_type_'+id).val(value[0]);
	$('#logistics_price_'+id).val(value[1]);
	
	//单店总价-物流=商品总价
	zj=$('#s_csumprice_'+id).html().replace(',','')*1-$('#show_cem_'+id).html()*1;
	
	$('#show_cem_'+id).html(roundAmount(value[1]));//选中的快递费
	$('#s_csumprice_'+id).html(roundAmount(value[1]*1+zj*1));
	
	count_all_price();
}
function count_all_price()
{	//计算本次购物总价,购物总价+所有物流价格
	var total=0;
	var stotal=$('.shop_total_price');
	for (var i=0;i<stotal.length;i++)
	{
		total+=stotal[i].innerHTML.replace(',','')*1;
	}
	
	$('#s_sumprice').html(roundAmount(total));
}
count_all_price();
function roundAmount(n)
{  
  var   s   =   ""   +   Math.round(n*100)/100  
  var   i   =   s.indexOf('.')  
  if(i<0)   return   s   +   ".00"  
  var   t=s.substring(0,   i   +   1)   +    
		  s.substring(i   +   1,   i   +   3)  
  if(i   +   2   ==   s.length)   t   +=   "0"  
  return   t  
}
$(function(){
	$('#submitToPay').click(function(){
		$('#form').validate({
			errorPlacement: function(error, element){
				Width=document.body.clientWidth/2-60;
				Height=document.body.clientHeight/2;
				$('.form-error').offset({top:Height,left:Width});
				$('.form-error').html(error);
			},      
			rules : {
				hidden_consignee_id:{
					required:true
				},
			},
			messages : {
				hidden_consignee_id:{
					required:'请设置收货地址'
				},
			},
		});
		$('#form').submit();
	});
											  
});
</script>  
</form>
<{else}>
<div class="noaddr">
<div></div>
您还没有设置收货地址<br><a href="main.php?m=member&s=admin_orderadder&t=pro">请点击这里设置！</a> 
</div>
<{/if}>
</section>
<{/if}>